package com.szp.drug.component.controller;

import com.github.pagehelper.PageInfo;
import com.szp.drug.entity.DrugCheck;
import com.szp.drug.util.ResultEntity;
import com.szp.drug.component.service.api.DrugCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 体检前端控制器
 * @author SuZePing
 * @create 2021-03-07 12:26
 * @E-mail suzeping10@126.com
 */
@Slf4j
@RestController
@RequestMapping("/check")
public class DrugCheckController {

	@Autowired
	private DrugCheckService checkService;

	/**
	 * 分页获取体检记录
	 * @param checkName
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/get/page.json")
	public ResultEntity<PageInfo<DrugCheck>> getPageInfo(
			@RequestParam(value = "checkName",defaultValue = "") String checkName,
			@RequestParam(value = "pageNum",defaultValue = "1") String pageNum,
			@RequestParam(value = "pageSize",defaultValue = "5") String pageSize
	){
		return checkService.getPageInfo(checkName, pageNum, pageSize);
	}

	/**
	 * 新增体检记录(并返回新增后总数量)
	 * @param check
	 * @return
	 */
	@PostMapping("/save.json")
	public ResultEntity<Integer> saveCheck(DrugCheck check){
		return checkService.saveCheck(check);
	}

	/**
	 * 删除记录
	 * @param checkId
	 * @return
	 */
	@PostMapping("/del.json")
	public ResultEntity<String> removeCheck(@RequestParam("checkId") String checkId){
		return checkService.removeCheck(checkId);
	}
}